package com.czy.owner.ui.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.LinearLayout;

import com.czy.owner.R;
import com.czy.owner.adapter.LogisticsAdapter;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.entity.LogisticsModel;
import com.czy.owner.ui.BaseFragment;
import com.easyrecycleview.EasyRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by yang on 2017/10/26.
 */

public class LogisticsFragment extends BaseFragment {
    @BindView(R.id.easy_recycleview)
    EasyRecyclerView easyRecycleview;
    private LogisticsAdapter adapter;
    private LogisticsModel logisticsModel = new LogisticsModel();
    private List<LogisticsModel> list = new ArrayList<>();

    @Override
    protected int attachLayoutRes() {
        return R.layout.common_fragment_easyrecycleview;
    }

    @Override
    protected void initInjector() {

    }


    public static BaseFragment myFragment(LogisticsModel logisticsModel) {
        LogisticsFragment fragment = new LogisticsFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("logisticsModel", logisticsModel);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void initViews() {
        boolean hasArgument = getArguments() != null;
        if(hasArgument){
            logisticsModel = (LogisticsModel) getArguments().getSerializable("logisticsModel");
        }
        easyRecycleview.setLayoutManager(new LinearLayoutManager(getActivity()));
        easyRecycleview.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL, R.drawable.shape_shopping_strategy_divider_decoration));
        easyRecycleview.setAdapterWithProgress(adapter = new LogisticsAdapter(getActivity()));
        if(logisticsModel!=null){
            list.add(logisticsModel);
            adapter.addAll(list);
        }
        if (adapter.getAllData() == null || adapter.getAllData().size() == 0) {
            easyRecycleview.setEmptyView(R.layout.view_empty_common);
            easyRecycleview.showEmpty();
        }
    }

    @Override
    protected void updateViews() {

    }


}
